#include "fileselectdialog.h"
#include "ui_fileselectdialog.h"
#include <QFileDialog>
#include <QDir>
#include <QPainter>
#include <QImage>


FileSelectDialog::FileSelectDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::FileSelectDialog)
{
    ui->setupUi(this);
}

FileSelectDialog::~FileSelectDialog()
{
    delete ui;
}

void FileSelectDialog::paintEvent(QPaintEvent *event)
{
    if(filePath.length()>0){
        // 显示一张图片
        QPainter painter(this);

        // 矩形区域
        QRect rect = ui->frame->rect();
        // 坐标系不一样，需要平移
        rect.translate(ui->frame->pos());
        QImage image(filePath);
        painter.drawImage(rect,image);

    }

}

void FileSelectDialog::on_m_btnSelect_clicked()
{

    QString rootPath = QString::fromUtf8("F:\\软件\\图片");

    QFileDialog *fileDlg = new QFileDialog();
    fileDlg->setDirectory(rootPath);
    fileDlg->setWindowTitle("选择图片文件目录");
//    fileDlg->setFilter();
    if(fileDlg->exec() == QFileDialog::Accepted){
        ui->m_filePath->setText(filePath);
        filePath = fileDlg->selectedFiles()[0];
        update();
    }



}
